package com.stylefeng.guns.modular.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.common.persistence.model.CpciaNews;
import com.stylefeng.guns.common.persistence.model.OperationLog;
import com.stylefeng.guns.modular.system.dao.CpciaNewsDao;
import com.stylefeng.guns.modular.system.service.ICpciaNewsService;

@Service
@Transactional
public class CpciaNewsServiceImpl implements ICpciaNewsService {

    @Autowired
    CpciaNewsDao cpciaNewsDao;

  /*  @Resource
    CpciaNewsMapper cpciaNewsMapper;*/

    @Override
    public void addDict(String dictName, String dictValues) {
    	
    	
    	
      /*  //判断有没有该字典
        List<Dict> dicts = cpciaNewsMapper.selectList(new EntityWrapper<Dict>().eq("name", dictName).and().eq("pid", 0));
        if(dicts != null && dicts.size() > 0){
            throw new BussinessException(BizExceptionEnum.DICT_EXISTED);
        }

        //解析dictValues
        List<Map<String, String>> items = parseKeyValue(dictValues);

        //添加字典
        Dict dict = new Dict();
        dict.setName(dictName);
        dict.setNum(0);
        dict.setPid(0);
        this.dictMapper.insert(dict);

        //添加字典条目
        for (Map<String, String> item : items) {
            String num = item.get(MUTI_STR_KEY);
            String name = item.get(MUTI_STR_VALUE);
            Dict itemDict = new Dict();
            itemDict.setPid(dict.getId());
            itemDict.setName(name);
            itemDict.setNum(Integer.valueOf(num));
            this.dictMapper.insert(itemDict);
        }*/
    }

    @Override
    public void editDict(Integer dictId, String dictName, String dicts) {
        //删除之前的字典
        this.delteDict(dictId);

        //重新添加新的字典
        this.addDict(dictName,dicts);
    }

    @Override
    public void delteDict(Integer dictId) {
  /*      //删除这个字典的子词典
        Wrapper<Dict> dictEntityWrapper = new EntityWrapper<>();
        dictEntityWrapper = dictEntityWrapper.eq("pid", dictId);
        dictMapper.delete(dictEntityWrapper);

        //删除这个词典
        dictMapper.deleteById(dictId);*/
    }

	@Override
	public void insertCpciaNews(CpciaNews cpciaNews) {
		// TODO Auto-generated method stub
		cpciaNewsDao.insert(cpciaNews);
	}
	
	@Override
	public CpciaNews selectById(String id) {
		// TODO Auto-generated method stub
		CpciaNews cpciaNews = cpciaNewsDao.selectById(id);
		return cpciaNews;
	}
	@Override
	public List<CpciaNews> selectByTitle(String title) {
		// TODO Auto-generated method stub
		Map<String, Object> columnMap = new HashMap<String, Object>();
		columnMap.put("title", title);
		List<CpciaNews> cpciaNewsList = cpciaNewsDao.selectByMap(columnMap);
		return cpciaNewsList;
	}
	
	@Override
	public List<Map<String, Object>>  getCpciaNews( Page<CpciaNews> page) {
		List<Map<String, Object>> result = cpciaNewsDao.getCpciaNews(page);
		return result;
	} 
}
